/* This program is free software. It comes without any warranty, to
 * the extent permitted by applicable law. You can redistribute it
 * and/or modify it under the terms of the Do What The Fuck You Want
 * To Public License, Version 2, as published by Sam Hocevar. See
 * http://sam.zoy.org/wtfpl/COPYING for more details. */ 
package de.rockon.fuzzy.controller.operators.defuzzyfy;

import de.rockon.fuzzy.controller.model.FuzzySet;
import de.rockon.fuzzy.controller.model.enums.DefuzzyfyType;
import de.rockon.fuzzy.controller.util.ModelUtil;

/**
 * Defuzzyfizierungsalgorithmus welcher das letzte Maximum ermittelt
 */
public class AvgMaximumDefuzzyfier extends AbstractDefuzzyfier {

	/**
	 * Konstruktor
	 */
	public AvgMaximumDefuzzyfier(FuzzySet resultSet) {
		super(resultSet);
	}

	@Override
	public double defuzzyfy() {
		double min = ModelUtil.defuzzyfy(resultSet, DefuzzyfyType.FIRST_MAXIMUM);
		double max = ModelUtil.defuzzyfy(resultSet, DefuzzyfyType.LAST_MAXIMUM);

		return (min + max) / 2;
	}

	@Override
	public String getDescription() {
		return "Defuzzyfizierungsalgorithmus welcher das letzte Maximum ermittelt";
	}

	@Override
	public String toString() {
		return "AvgMaximum";
	}
}